package com.qqtech.qquan.order.service;

import java.util.List;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.stereotype.Service;

import com.qqtech.core.common.util.StringUtil;
import com.qqtech.core.frame.dao.BaseDao;
import com.qqtech.core.frame.model.PageKit;
import com.qqtech.core.frame.model.PageOrder;
import com.qqtech.core.frame.service.BaseServiceImpl;
import com.qqtech.qquan.order.dao.OrderItemDao;
import com.qqtech.qquan.order.model.OrderItem;
import com.qqtech.qquan.order.model.OrderItemQuery;
import com.qqtech.qquan.order.model.OrderItemVo;

import jersey.repackaged.com.google.common.collect.Lists;

@Service
public class OrderItemServiceImpl extends BaseServiceImpl<OrderItem>
		implements OrderItemService {
	public static final Logger log = LoggerFactory.getLogger(OrderItemServiceImpl.class);
	
	@Resource
	private OrderItemDao orderItemDao;

	@Override
	protected BaseDao<OrderItem> getBaseDao() {
		return orderItemDao;
	}

	@Override
	public List<OrderItem> findByOrderNo(String orderNo) {
		if (StringUtil.isBlank(orderNo)) {
			return null;
		} else {
			OrderItemQuery q = new OrderItemQuery();
			q.setOrderNo(orderNo);
			return orderItemDao.queryList(q);
		}
	}
	
	@Override
	public Page<OrderItemVo> queryPageList4Admin(OrderItemQuery query, Pageable pageable) {
		return orderItemDao.queryPageList4Admin(query, pageable);
	}
	
	@Override
	public List<OrderItemVo> queryList4Admin(OrderItemQuery query, Pageable pageable) {
		return orderItemDao.queryList4Admin(query, pageable);
	}
	
	@Override
	public int queryCount4Admin(OrderItemQuery query) {
		return orderItemDao.queryCount4Admin(query);
	}
	
	@Override
	public List<OrderItemVo> getListByItemIds(List<Integer> orderItemIds) {
		if(orderItemIds!=null && orderItemIds.size()>0){
			Pageable pageKit2 = new PageKit(1, Integer.MAX_VALUE,new PageOrder(Direction.ASC, "id"));
			OrderItemQuery orderItemQuery = new OrderItemQuery();
			orderItemQuery.setIncludeIds(orderItemIds);
			return orderItemDao.queryList(orderItemQuery, pageKit2);
		}else{
			return Lists.newArrayList();
		}
	}
	
}